package com.boarsoft.boar.gateway.demo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.boarsoft.flow.core.bean.ProcessHandler;
import com.boarsoft.rpc.core.RpcContext;

@Component("macRpcServiceProxy")
public class MacRpcServiceProxy implements ProcessHandler {

	@Autowired
	protected RpcContext rpcContext;

	/** 可选，通过XML配置注入，来自 mac-rpc/consumer.xml */
	protected ProcessHandler target;
	
	protected String handler;

	@Override
	public Object process(String entry, Object data, Throwable throwable) throws Throwable {
		// TODO 取出 POD ID
		ProcessHandler handler = target;
		if (target == null) {
			handler = rpcContext.getBean(entry, ProcessHandler.class);
		}
		RpcContext.specify2("0"); // POD ID
		try {
			handler.process(entry, data, throwable);
		} finally {
			RpcContext.specify2(null);
		}
		return data;
	}

	public ProcessHandler getTarget() {
		return target;
	}

	public void setTarget(ProcessHandler target) {
		this.target = target;
	}

}
